﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Bam
{
    class Input_Keyboard : Input
    {
        public KeyboardState prev_state;

        public Input_Keyboard(int input_index)
        {
            //int input_index = 0;
            button_map = new Dictionary<BUTTON_ACTION, Keys>();
            //set default keyboard button map
            switch (input_index)
            {
                case 0:
                    button_map.Add(BUTTON_ACTION.left, Keys.A);
                    button_map.Add(BUTTON_ACTION.right, Keys.D);
                    button_map.Add(BUTTON_ACTION.up, Keys.W);
                    button_map.Add(BUTTON_ACTION.down, Keys.S);
                    button_map.Add(BUTTON_ACTION.fire, Keys.Space);
                 break;
                case 1:
                    button_map.Add(BUTTON_ACTION.left, Keys.Left);
                    button_map.Add(BUTTON_ACTION.right, Keys.Right);
                    button_map.Add(BUTTON_ACTION.up, Keys.Up);
                    button_map.Add(BUTTON_ACTION.down, Keys.Down);
                    button_map.Add(BUTTON_ACTION.fire, Keys.Enter);
                    break;
            }
            
            prev_state = Keyboard.GetState();
        }

        public override bool is_pressed(BUTTON_ACTION action)
        {
            Keys cur_key = this.button_map[action];
            Console.WriteLine("cur state:" + Keyboard.GetState().IsKeyDown(cur_key));
            Console.WriteLine("prev state:" + prev_state.IsKeyDown(cur_key));
            if (Keyboard.GetState().IsKeyDown(cur_key) == true &&
                    prev_state.IsKeyDown(cur_key) == false)
                return true;
            else
                return false;
        }
        public override bool is_down(BUTTON_ACTION action)
        {
             Keys cur_key = button_map[action];

             return Keyboard.GetState().IsKeyDown(cur_key);
        }
        public override void update()
        {
            prev_state = Keyboard.GetState();
        }

    }

}
